#include <OgreRoot.h>
#include <OgrePrerequisites.h>
#include <string>
#include <OgreString.h>
#include <framelistener.h>
#include <OgreRenderSystem.h>

#define DLL_EXPORT __declspec(dllexport)

//TODO: more comments

using namespace Ogre;

//Get the object:

extern "C" DLL_EXPORT Root *getRoot(const char *pluginFileName, const char *configFileName, const char *logFileName)
{
    return new Root((String)pluginFileName, (String)configFileName, (String)logFileName);
}

//Destroy the Wrapper

extern "C" DLL_EXPORT void freeRoot(Root* ptr)
{
    delete ptr;
}

//Method callers

extern "C" DLL_EXPORT bool call_showConfigDialog(void* ptr)
{
    return ((Root*)ptr)->showConfigDialog();
}

extern "C" DLL_EXPORT void call_saveConfig(void* ptr)
{
    ((Root*)ptr)->saveConfig();
    return;
}

extern "C" DLL_EXPORT bool call_restoreConfig(void* ptr)
{
    return ((Root*)ptr)->restoreConfig();
}

extern "C" DLL_EXPORT RenderWindow *call_initialise(void* ptr, bool autoCreateWindow, const char* windowTitle, const char* customCapabilitiesConfig)
{
    return ((Root*)ptr)->initialise(autoCreateWindow, (String)windowTitle, (String)customCapabilitiesConfig);
}

extern "C" DLL_EXPORT RenderWindow *call_getAutoCreatedWindow(void *ptr)
{
    return ((Root*)ptr)->getAutoCreatedWindow();
}

extern "C" DLL_EXPORT void call_startRendering(void *ptr)
{
    ((Root*)ptr)->startRendering();
}

extern "C" DLL_EXPORT SceneManager *call_createSceneManager(void *ptr, SceneTypeMask typeMask, char * instanceName)
{
    return ((Root*)ptr)->createSceneManager(typeMask, (String)instanceName);
}

extern "C" DLL_EXPORT void call_addFrameListener(void *ptr, void *ptrToListener)
{
    ((Root*)ptr)->addFrameListener((FrameListenerWrapper*)ptrToListener);
}

extern "C" DLL_EXPORT bool call_renderOneFrame(Root *ptr)
{
	return ptr->renderOneFrame();
}

extern "C" DLL_EXPORT RenderSystem* call_getRenderSystem(Root *ptr)
{
	return ptr->getRenderSystem();
}

extern "C" DLL_EXPORT void call_queueEndRendering(Root* ptr)
{
	ptr->queueEndRendering();
}